<template>
  <div>
    <div v-for="(message, index) in messages" :key="index">{{ message }}</div>
    <form @submit.prevent="sendMessage">
      <input type="text" v-model="text" />
      <button type="submit">Send</button>
    </form>
  </div>
</template>

<script>
import axios from 'axios'
import chatApi, { senMessage } from '@/api/chat'
export default {
  name:"test",
  data() {
    return {
      text: '',
      messages: []
    }
  },
  methods: {
    sendMessage() {
      senMessage({ message: this.text,sessionId:88 })
    }
  },
  created() {
    const source = new EventSource('http://localhost:8888/chatgpt/stream')
    source.onmessage = event => {
      console.log(event.data)
      this.messages.push(event.data)
    }
  }
}
</script>
